function tijian_UpLoad(fileObj,memberId,memberName,serverStationCode){
	$("#memberId").val(memberId);		
	$("#serverStationCode").val(serverStationCode);		
	$("#upMemName").html(memberName);	
	tijian_file_change(fileObj);
}
function tijian_file_change(fileObj){
	var size=0;
	$(".fileName").each(function(){
		if($(this).val().length!=0){
			size++;
		}
	});
	if(size>7){
		zhyAlert("一次只能上传8张图！");
		return;
	}
	var arr = [ "jpg", "png", "bmp", "doc", "docx" ]
	var browserCfg =true;
    var ua = window.navigator.userAgent.toLowerCase();  
    if (ua.indexOf("msie")>=1){  
    	var safariVersion =  ua.match(/msie ([\d.]+)/)[1];
    	if(parseInt(safariVersion) <= 9){
    	    // 进行你所要的操作
    		 browserCfg= false;  
    	}		           
    }
    var fileSize=0;
    var obj_file = fileObj;  
    if(browserCfg){
        var fileS = obj_file.files;	
		if(fileS.length==0){return false;}
		var fileNames="";
		var length=fileS.length;			
		for (var i = 0; i < length; i++) {
			var name =fileS[i].name.substring(0,fileS[i].name.lastIndexOf("."));
			var type =fileS[i].name.substring(fileS[i].name.lastIndexOf(".")+1).toLowerCase();
			if($.inArray(type, arr)==-1)
			{
				zhyAlert("文件"+name+"的类型不匹配");	
				clearFile();
				return false;
			}
			var size =fileS[i].size/ 1024;
			if(size>4000){
				zhyAlert("文件"+name+"大小超过4M");	
				clearFile();
				return false;				
			}
			fileSize=fileSize+size;
		}
    }else{
    	fileSize=4000;
    }
	var pbytesRead=0;
	var rate=0;
	 $.ajaxFileUpload(
	    {
	        url: '../imageUpload/upload_files', 
	        data:{lineType:"klh"},
	        secureuri: false, //一般设置为false
	        fileElementId: fileObj.id,
	        dataType:'json',
	       	success: function (data, status){  //服务器成功响应处理函数
	            if(data[0].rs==1){
	            	if(data[0].paths.length>0){
	            		var memberId=$("#memberId").val();
	            		var str = html_decode(JSON.stringify(data[0])).replace(new RegExp(/(&)/g),"'and'");
	            		var json = eval("("+str+")");
	            		var fileUrl = json.paths[0].url;
	            		var fileName = data[0].sourceNames[0];
	            		var num=0;
	            		var arrName=new Array();
	            		var arrUrl=new Array();
	            		$(".fileName").each(function(){
	            			if($(this).val().length!=0){
	            				num++;
	            			}
	            		});
	            		var count = num+1;
	            		$("#fileName"+count).val(fileName);
            			$("#fileUrl"+count).val(fileUrl);
            			 
            			$("#name"+count).text(fileName);
            			document.getElementById("see"+count).href=fileUrl;
            			
            			for (var i=1; i<=count; i++){
            				$(".name"+i).css('display','block');
            			} 
            			
	            		var showAttFun = function(){           
	            		if(pbytesRead>=fileSize || rate==99){			                       					
           	            	 	hidePop();
               				 	window.clearInterval(showAttId);
               				 	deleteM(this,'zhy_popa_0');                      					
                            }     
                        };  			                               
                        var showAttId = window.setInterval(showAttFun,200); 
            		}	            		
            	}else{	   
            		window.clearInterval(intId);
    				
	            	 	hidePop();
    				zhyAlert("文件上传失败");	
            	}
	        },
	        error: function (data, status, e)//服务器响应失败处理函数
	        {
	        	window.clearInterval(intId);  
				
        	 	hidePop();
				zhyAlert("文件上传失败");	
	        	
	        },complete:function(){
	        	
	        	clearFile();
	        }
	    });
	 showPop(null,'zhy_popa_progress');

	 var eventFun = function(){           
		 pbytesRead=pbytesRead+getRandom(300);			
		 rate=parseInt(pbytesRead/fileSize*100);
		 if(rate>=100){
			 rate=99;
		 }
		 if(pbytesRead>fileSize){
			 pbytesRead=fileSize;
		 }
         $('#proBar').css('width',rate+''+'%');  
         $('#divWidth').empty();  
         $('#divWidth').append(rate+"%");   
         if(rate == 99){  
             window.clearInterval(intId);  
         }     
     };  
     $("#proBar").show();
     var intId = window.setInterval(eventFun,500);  
};

function clearFile()
{
	document.getElementById("tijian_file").outerHTML += '';//清空IE的
	document.getElementById("tijian_file").value = "";//可以清空火狐的
}
function html_decode(str) 
{ 
    var s = ""; 
    if (str.length == 0) return ""; 
    s = str.replace(/&amp;/g, "&"); 
    s = s.replace(/&lt;/g, "<"); 
    s = s.replace(/&gt;/g, ">"); 
    s = s.replace(/&nbsp;/g, " "); 
    s = s.replace(/&#39;/g, "\'"); 
    s = s.replace(/&quot;/g, "\""); 
    s = s.replace(/<br\/>/g, "\n"); 
    return s; 
} 
//在子页面显示弹框
function showPop(obj,className,id){
	$(".zhy_zhezhao_pop").show();
	var top = document.body.scrollTop||document.documentElement.scrollTop;
	var this_h = $("." + className).height();
	var win_h = ($('html',parent.document).height()-this_h-100)/2
	$(".zhy_zhezhao_pop").height($("html").height());
	var this_h = $("." + className).height();
	top= top +win_h;
	$("." + className).css("top", top).show().siblings(".zhy_popa").hide();
}

function hidePop() {
	$(".zhy_zhezhao_pop").hide();
	$(".zhy_popa").hide();
	$("#proBar").hide();
	$('#proBar').css('width','0%');  
	$("#divWidth").empty();  
}
function getRandom(n){
    return Math.floor(Math.random()*n+1)
}

function save(){ 
	var remark =$("#acc_remark").val();
	$("#remark").val(remark)
	var size=0;
	$(".fileName").each(function(){
		if($(this).val().length!=0){
			size++;
		}
	});
	if(size<1){
		zhyAlert("请最少上传一个附件！");
		return;
	}
	if(remark.length>120){
		zhyAlert("备注请输入120个以内的字符！");
		return;
	}
	$.ajax({
        cache: true,
        type: "POST",
        url:'../abilityAttachment/addAttachment',
        data:$('#acc_save').serialize(),// 你的formid
        async: false,
        success: function(data) {
        	if(data.data){
        		zhyAlert("保存成功");
        		var id = $("#accId").val();
        		if(id.length>0){
        			InitAccTable(0);
        		}else{
        			InitTable(0);
        		}
        		hideAcc();
        	}else{
        		zhyAlert("保存失败");
        	}
        }
    }); 
}

function showDel(num){
	$("#fileName"+num).val("");
	$("#fileUrl"+num).val("");
	
	$("#name"+num).text("");
	document.getElementById("see"+num).href="";
	$(".name"+num).css('display','none'); 
	var num=0;
	var arrName=new Array();
	var arrUrl=new Array();
	var arrSeeName=new Array();
	var arrSeeUrl=new Array();
	$(".fileName").each(function(){
		if($(this).val().length!=0){
			num++;
			arrName.push($(this).val());
		}
	});
	$(".fileUrl").each(function(){
		if($(this).val().length!=0){
			arrUrl.push($(this).val());
		}
	});
	$(".fileName").val("");
	$(".fileUrl").val("");
	for (var i=1; i<=arrName.length; i++){
		$("#fileName"+i).val(arrName[i-1]);
		$("#fileUrl"+i).val(arrUrl[i-1]);
		$("#name"+i).text(arrName[i-1]);
		$("#see"+i).attr("href",arrUrl[i-1]);
		$(".name"+i).css('display','block');
	}
	for (var i=(arrName.length+1); i<=8; i++){
		$(".name"+i).css('display','none');
	}
}

function hideAcc(){
	hidePopC();
	$(".fileName").val("");
	$(".fileUrl").val("");
	$(".name").text("");
	$(".see").attr("href","");
	
	for (var i=1; i<=8; i++){
		$(".name"+i).css('display','none');
	}
	$("#accId").val("");
	$("#remark").val("");
	$("#acc_remark").val("");
}

//显示删除提示框
function delAcc(id,memberId,serverStationCode){
	$("#delId").val(id);	
	$("#delmemberId").val(memberId);	
	$("#delserverStationCode").val(serverStationCode);	
	deleteM(this,'dialog_0');	
}
//显示弹框
function deleteM(obj,className){
	$(".zhy_zhezhao_pop").show();
	var top = $('html',parent.document).scrollTop(); //兼容scrolltop写法
	var win_h = $("body",parent.document).height();
	$(".zhy_zhezhao_pop").height($("html").height());
	var this_h = $("." + className).height();
	var cha = win_h - this_h-160;
	if (cha > 0) {
		top += cha / 2;
	} else {
		top += 0;
	}
	$("." + className).css("top", top).show();
}
function AccDel(){
	var id = $("#delId").val();	
	var memberId = $("#delmemberId").val();	
	var serverStationCode = $("#delserverStationCode").val();	
	$.ajax({
        cache: true,
        type: "POST",
        url:'../abilityAttachment/delAttachment',
        data:{
        	accId:id,
        	memberId:memberId,
        	serverStationCode:serverStationCode
        },
        async: false,
        success: function(data) {
        	if(data.data){
        		zhyAlert("删除成功");
        		hidePopC();
        		$("#delId").val("");	
        		$("#delmemberId").val("");	
        		$("#delserverStationCode").val("");	
        		InitAccTable(0);
        	}else{
        		zhyAlert("删除失败");
        	}
        }
    }); 
}
function seeAcc(id,memberId,serverStationCode,remark){
	var name = $("#name").val();
	$("#upMemName").html(name);	
	
	$("#accId").val(id);
 	$("#acc_remark").val(remark);
 	$("#remark").val(remark);
	textareaLeftWords(document.getElementById("acc_remark"));
	$.ajax({
        cache: true,
        type: "POST",
        url:'../abilityAttachment/seeAttachment',
        data:{
        	accId:id,
        	memberId:memberId,
        	serverStationCode:serverStationCode
        },
        async: false,
        success: function(data) {
        	var file = data.file;
        	var str = JSON.stringify(file); 
       	 	var json =  jQuery.parseJSON(str);
       	 	if(json){
       	 		
       	 		if(json.f1name&&json.f1url){
	       	 		$("#name1").text(json.f1name);
	       			document.getElementById("see1").href=json.f1url;
	       			$("#fileName1").val(json.f1name);
	       			$("#fileUrl1").val(json.f1url);
	       			$(".name1").css('display','block');
       	 		}
       	 		if(json.f2name&&json.f2url){
	       	 		$("#name2").text(json.f2name);
	       			document.getElementById("see2").href=json.f2url;
	       			$("#fileName2").val(json.f2name);
	       			$("#fileUrl2").val(json.f2url);
	       			$(".name2").css('display','block'); 
       	 		}
       	 		if(json.f3name&&json.f3url){
	       	 		$("#name3").text(json.f3name);
	       			document.getElementById("see3").href=json.f3url;
	       			$("#fileName3").val(json.f3name);
	       			$("#fileUrl3").val(json.f3url);
	       			$(".name3").css('display','block'); 
       	 		}
	       	 	if(json.f4name&&json.f4url){
		       	 	$("#name4").text(json.f4name);
		    		document.getElementById("see4").href=json.f4url;
		    		$("#fileName4").val(json.f4name);
		    		$("#fileUrl4").val(json.f4url);
		    		$(".name4").css('display','block'); 
	   	 		}
	       	 	if(json.f5name&&json.f5url){
		       	 	$("#name5").text(json.f5name);
		    		document.getElementById("see5").href=json.f5url;
		    		$("#fileName5").val(json.f5name);
		    		$("#fileUrl5").val(json.f5url);
		    		$(".name5").css('display','block');  
	   	 		}
	       	 	if(json.f6name&&json.f6url){
		       	 	$("#name6").text(json.f6name);
		    		document.getElementById("see6").href=json.f6url;
		    		$("#fileName6").val(json.f6name);
		    		$("#fileUrl6").val(json.f6url);
		    		$(".name6").css('display','block');   
	   	 		}
	       	 	if(json.f7name&&json.f7url){
		       	 	$("#name7").text(json.f7name);
		    		document.getElementById("see7").href=json.f7url;
		    		$("#fileName7").val(json.f7name);
		    		$("#fileUrl7").val(json.f7url);
		    		$(".name7").css('display','block'); 
	   	 		}
	       	 	if(json.f8name&&json.f8url){
		       	 	$("#name8").text(json.f8name);
		    		document.getElementById("see8").href=json.f8url;
		    		$("#fileName8").val(json.f8name);
		    		$("#fileUrl8").val(json.f8url);
		    		$(".name8").css('display','block'); 
	   	 		}
	       	 	deleteM(this,'zhy_popa_0');   
       	 	}
        }
    }); 
}